﻿using System;
using Cpuss.ReportGenerator;
using NUnit.Framework;

namespace Cpuss.Console.Tests
{

    /// <summary>
    /// Tests for StrategyFactory.
    /// </summary>
    [TestFixture]
    public class StrategyFactoryTest
    {

        /// <summary>
        /// Check to see that the strategy is not null.
        /// </summary>
        [Test]
        public void ConstructorlessStrategyNotNullTest()
        {
            object[] args = new object[0];
            StrategyFactory factory = new StrategyFactory("FirstComeFirstServed", args);

            IStrategy actual = factory.CreateInstance();

            Assert.IsNotNull(actual);
        }

        /// <summary>
        /// Check to see that the correct exception is thrown when the strategy provided is null.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void StrategyNullTest()
        {
            object[] args = new object[0];
            StrategyFactory actual = new StrategyFactory(null, args);
        }

        /// <summary>
        /// Check to see that the correct exception is thrown when the strategy provided is null.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ArgumentsNullTest()
        {
            StrategyFactory actual = new StrategyFactory("Test", null);
        }

        /// <summary>
        /// Check to see that the strategy is not null.
        /// </summary>
        [Test]
        public void ConstructorHasArgsNotNullTest()
        {
            object[] args = { 2 };
            StrategyFactory factory = new StrategyFactory("ShortestJobFirst", args);

            IStrategy actual = factory.CreateInstance();

            Assert.IsNotNull(actual);
        }

        /// <summary>
        /// Check to see that null is returned when trying to create a strategy that doesn'args exist in the plugin assemblies.
        /// </summary>
        [Test]
        public void StrategyUnkownTest()
        {
            object[] args = new object[0];
            StrategyFactory factory = new StrategyFactory("MultiLevelQueue", args);

            IStrategy actual = factory.CreateInstance();

            Assert.IsNull(actual);
        }

    }

}
